<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>imock 二叉树</title>
</head>

<body>
	<script type="text/javascript">
		function BinaryTree() {
			let Node = function (key) {
				this.key = key;
				this.left = null;
				this.right = null;
			};
			let root = null;
			let insertNode = function (node, newNode) {
				if (newNode.key < node.key) {
					if (node.left === null) {
						node.left = newNode;
					} else {
						insertNode(node.left, newNode);
					}
				} else {
					if (node.right === null) {
						node.rigth = newNode;
					} else {
						insertNode(root.right, newNode);
					}
				}
			}
			this.insert = function (key) {
				let newNode = new Node(key);
				if (root === null) {
					root = newNode;
				} else {
					insertNode(root, newNode);
				}
			}
		};

		let nodes = [8, 3, 10, 1, 6, 14, 4, 7, 13];
		let binaryTree = new BinaryTree();
		nodes.forEach(function (key) {
			binaryTree.insert(key);
		})
	</script>
</body>

</html>